package com.zzyl.controller.web;

import com.zzyl.base.ResponseResult;
import com.zzyl.controller.BaseController;
import com.zzyl.entity.Room;
import com.zzyl.service.RoomService;
import com.zzyl.vo.RoomVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class RoomController extends BaseController {
    @Autowired
    private RoomService roomService;

    //新增房间
    @PostMapping("/room/add")
    public ResponseResult save(@RequestBody Room room){
        roomService.saveOrUpdateRoom(room);
        return success();
    }
    //更新房间
    @PutMapping("/room/update")
    public ResponseResult update(@RequestBody Room room){
        roomService.saveOrUpdateRoom(room);
        return success();
    }

    //查询指定楼层下的房间
    @GetMapping("/room/getRoomsByFloorId/{floorId}")
    public ResponseResult findById(@PathVariable("floorId") Long floorId){
        List<RoomVo> roomVoList = roomService.getByFloorId(floorId);
        return success(roomVoList);
    }

    //查询房间详情
    @GetMapping("/room/get/{id}")
    public ResponseResult findByRoomId(@PathVariable("id") Long id){
        RoomVo roomVoList = roomService.findByRoomId(id);
        return success(roomVoList);
    }
    //删除房间
    @DeleteMapping("/room/delete/{id}")
    public ResponseResult delete(@PathVariable("id") Long id){
        roomService.removeById(id);
        return success();
    }

}
